package com.example.demo.controller;

import com.example.demo.entity.Result;
import com.example.demo.entity.Topic;
import com.example.demo.entity.TopicOption;
import com.example.demo.service.Topicservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("topic")
public class TopicController {

    @Autowired
    Topicservice topicservice;

    @RequestMapping("list")
    @ResponseBody
    public List<Topic> list (String name){
        List<Topic> list = topicservice.list(name);
        return list;
    }
    @RequestMapping
    public String topic (String name){

        return "topic/specification";
    }
    @RequestMapping("save")
    @ResponseBody
    public Result add (@RequestBody TopicOption topicOption){
        System.out.println(topicOption);
        topicservice.add(topicOption);
        return new Result(true,"");
    }
    @RequestMapping("del")
    @ResponseBody
    public Result del (Integer[] ids){

        topicservice.del(ids);
        return new Result(true,"成功");
    }
    @RequestMapping("update")
    @ResponseBody
    public Result update (@RequestBody TopicOption topicOption){
        topicservice.update(topicOption);
        return new Result(true,"");
    }

    @RequestMapping("getTopicOption")
    @ResponseBody
    public TopicOption getTopicOption(Integer tid){
        return topicservice.getTopicOption(tid);
    }

    /*//获取到题
    @RequestMapping("listoption")
    @ResponseBody
    public List<TopicOption> listoption(){
        List<TopicOption> list =topicservice.listoption();
        return list;
    }*/




}
